"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function _sanitize(t,e){var o=document.createElement("a");o.href=t;var l=o.href.slice(0,o.href.indexOf(":"));return e.indexOf(l)>-1}function relativeUrl(t){var e=location,o=document.createElement("a");return o.href=t,e.origin!=o.origin?o.href:e.pathname!=o.pathname||e.search!=o.search?o.pathname+o.search+o.hash:e.href==o.href?o.hash||o.pathname+o.search+o.hash:o.hash}function getFigureValueByUrl(t,e){var o=void 0;return(o=t.match(/^(https?):\/\/(www\.)?youtube\.com\/watch.*v=([a-zA-Z0-9_-]+)/i))||(o=t.match(/^(https?):\/\/(www\.)?youtu\.be\/([a-zA-Z0-9_-]+)/i))?e({embed:"/embed/youtube?url="+encodeURIComponent(t)}):(o=t.match(/^(https?):\/\/(www\.)?vimeo\.com\/(\d+)/i))?e({embed:"/embed/vimeo?url="+encodeURIComponent(t)}):(o=t.match(/^(https?):\/\/(www\.|mobile\.)?twitter\.com\/(.+)\/status\/(\d+)/i))?e({embed:"/embed/twitter?url="+encodeURIComponent(t)}):(o=t.match(/^(https?):\/\/(t\.me|telegram\.me|telegram\.dog)\/([a-zA-Z0-9_]+)\/(\d+)/i))?e({embed:"/embed/telegram?url="+encodeURIComponent(t)}):(o=t.match(/^data:(image\/gif|image\/jpe?g|image\/png|video\/mp4);base64,(.*)$/))?e("video/"==o[1].substr(0,6)?{video:t}:{image:t}):((o=t.match(/^(https?):\/\/\S+/i))&&!function(){var o=document.createElement("img"),l=document.createElement("video");l.setAttribute("preload","auto");var r=0,i=!1,a=function(t){r++,i||(s(t),i=!0)},n=function(){r++,r>1&&!i&&(s("none"),i=!0)},s=function(o){e("photo"==o?{image:t}:"video"==o?{video:t}:!1)};o.addEventListener("load",function(){a("photo")}),l.addEventListener("loadeddata",function(){a("video")}),o.addEventListener("error",n),l.addEventListener("error",n),o.setAttribute("src",t),l.setAttribute("src",t)}(),e(!1))}function _resizeIframe(t,e,o){$("iframe").map(function(){var l=null;try{l=this.contentWindow}catch(r){}if(l&&l==t){var i=o/e;this.setAttribute("width","640"),this.setAttribute("height",Math.round(640*i)+""),this.parentNode&&this.parentNode.classList.contains("iframe_helper")&&(this.parentNode.style.paddingTop=100*i+"%"),window.quill&&quill.updateSelection(Quill.sources.USER)}})}function initQuill(){function t(t,e){return[t,function(t,o){return o.compose((new Delta).retain(o.length(),e))}]}function e(t){var e=a.scroll.line(t),o=_slicedToArray(e,2),l=o[0],r=o[1];return a.getText(t,l.length()-r)}function o(t){var o=e(t);return!o||"\n"==o}function l(t,e,l){var r=void 0,i=e.index;e.length>0&&a.scroll.deleteAt(i,e.length);var n=o(i),s=!1,u=a.scroll.descendant(BreakBlot,i),c=_slicedToArray(u,1);if(r=c[0])(!r.prev||r.prev instanceof BreakBlot)&&(a.scroll.deleteAt(--i,1),s=!0);else{var d=a.scroll.descendant(BreakBlot,i-1),p=_slicedToArray(d,1);r=p[0],r&&(a.scroll.deleteAt(--i,1),s=!0)}var h=a.scroll.descendant(SingleLineBlot,i),f=_slicedToArray(h,1);if(r=f[0],r||s||!t)a.insertText(i,"\n",Quill.sources.USER),a.setSelection(++i,Quill.sources.USER),(l.format.blockHeader||l.format.blockSubheader||l.format.blockBlockquote||l.format.blockPullquote)&&n&&a.formatLine(i,1,{blockHeader:!1,blockSubheader:!1,blockBlockquote:!1,blockPullquote:!1},Quill.sources.USER);else{a.insertEmbed(i,"textBreak",!0,Quill.sources.USER);var _=a.scroll.descendant(BreakBlot,i),m=_slicedToArray(_,1);r=m[0],!r||r.next||r.prev&&r.prev instanceof BreakBlot||(a.insertEmbed(++i,"textBreak",!0,Quill.sources.SILENT),a.setSelection(i,0,Quill.sources.SILENT))}return a.selection.scrollIntoView(),!1}function r(t){var e=a.scroll.line(t.index),o=_slicedToArray(e,2),l=o[0],r=o[1];if(l){var i=l.domNode.innerText,n=i.substr(0,r),s=void 0;if(s=n.match(/(^|\s)((?:https?|tg):\/\/\S+|www\.\S+)$/)){var u=s[2],c=u.length;"www."==u.substr(0,4)&&(u="http://"+u);var d=a.scroll.descendants(LinkBlot,t.index-c,c);d.length||a.formatText(t.index-c,c,"link",u,Quill.sources.USER)}}return!0}var i=draftGet();i&&$("#_tl_editor").html(i);var a=new MyQuill("#_tl_editor",{readOnly:!0,fileSizeLimit:T.uploadEnabled?5242880:0,fileSizeLimitCallback:function(){showError("File too big (up to 5 MB allowed)")},updatePhoto:updatePhoto,formats:["bold","italic","underline","strike","code","link","textBreak","blockTitle","blockAuthor","blockHeader","blockSubheader","blockBlockquote","blockPullquote","blockDivider","blockFigure","code-block","list"],modules:{clipboard:{matchers:[t("h2",{blockHeader:!0}),t("h5",{blockSubheader:!0}),t("h6",{blockSubheader:!0}),["img",function(t,e){return t.src&&_sanitize(t.src,["http","https","data"])?(new Delta).insert({blockFigure:{image:t.src,caption:t.alt||""}}):new Delta}],["video",function(t,e){return t.src&&_sanitize(t.src,["http","https","data"])?(new Delta).insert({blockFigure:{video:t.src}}):new Delta}],["br",function(t,e){return t.classList.contains("inline")?(new Delta).insert({textBreak:!0}):e}]]},keyboard:{bindings:{indent:{handler:function(){return!0}},outdent:{handler:function(){return!0}},tab:{key:Keyboard.keys.TAB,handler:function(){return!0}},"required enter":{key:Keyboard.keys.ENTER,collapsed:!0,shiftKey:null,format:["blockTitle","blockAuthor"],suffix:/^$/,handler:function(t,e){var o=this.quill.scroll.descendant(FieldBlot,t.index),l=_slicedToArray(o,1),r=l[0];return r&&r.next&&!$(r.next.domNode).text()?(this.quill.setSelection(r.next.offset(this.quill.scroll),0,Quill.sources.USER),!1):(this.quill.insertText(t.index,"\n",Quill.sources.USER),!1)}},"required tab prev":{key:Keyboard.keys.TAB,shiftKey:!0,handler:function(t,e){var o=null;if(t.length>0){var l=a.scroll.descendants(Block,t.index,t.length);if(1!=l.length)return!0;o=l[0]}else{var r=a.scroll.descendant(Block,t.index),i=_slicedToArray(r,1);o=i[0]}if(null!=o&&null!=o.prev&&o.prev instanceof FieldBlot){var n=o.prev.offset(a.scroll),s=o.prev.length();return a.setSelection(n,s>1?s:0,Quill.sources.USER),!1}return!0}},"required tab next":{key:Keyboard.keys.TAB,shiftKey:!1,handler:function(t,e){var o=null;if(t.length>0){var l=a.scroll.descendants(Block,t.index,t.length);if(1!=l.length)return!0;o=l[0]}else{var r=a.scroll.descendant(Block,t.index),i=_slicedToArray(r,1);o=i[0]}if(null!=o&&o instanceof FieldBlot&&null!=o.next){var n=o.next.offset(a.scroll);if(o.next instanceof FieldBlot){var s=o.next.length();a.setSelection(n,s>1?s:0,Quill.sources.USER)}else a.setSelection(n,0,Quill.sources.USER);return!1}return!0}},"no tab":{key:Keyboard.keys.TAB,shiftKey:null,handler:function(t,e){return!1}},"detect embed":{key:Keyboard.keys.ENTER,collapsed:!0,handler:function(t,e){var o=a.scroll.line(t.index),l=_slicedToArray(o,2),r=l[0],i=l[1];return r&&!function(){var e=r.domNode.innerText,o=e.substr(0,i),l=void 0;if(l=o.match(/(^|\s)(https?:\/\/\S+)$/)){var n=l[2],s=a.scroll.descendants(LinkBlot,t.index-n.length,n.length);s.length||a.formatText(t.index-n.length,n.length,"link",n,Quill.sources.USER),o.substr(0,i-n.length).trim().length||"P"!=r.domNode.tagName||getFigureValueByUrl(n,function(t){if(t){var e=r.offset(a.scroll);return a.updateContents((new Delta).retain(e)["delete"](o.length).insert({blockFigure:t}),Quill.sources.USER),hideBlocksTooltip(),!1}})}}(),!0}},"divider autofill":{key:Keyboard.keys.ENTER,collapsed:!0,prefix:/^([-*])\1{2,}$/,handler:function(t,e){var o=a.scroll.line(t.index),l=_slicedToArray(o,2),r=l[0];l[1];if(r&&"P"==r.domNode.tagName){var i=r.offset(a.scroll),n=(new Delta).retain(i)["delete"](r.length()).insert({blockDivider:!0});return r.next||n.insert("\n"),a.updateContents(n,Quill.sources.USER),!1}return!0}},"break":{key:Keyboard.keys.ENTER,shiftKey:!0,handler:l.bind(null,!0)},enter:{key:Keyboard.keys.ENTER,handler:l.bind(null,!1)},"detect link":{key:" ",collapsed:!0,handler:r},"cancel placeholder":{key:Keyboard.keys.ESCAPE,handler:function(t,e){return checkOncePlaceholder(),this.quill.updateSelection(Quill.sources.USER),checkTooltips(t),checkRequiredBlots(a),checkBlotPlaceholder(a),!0}},"list autofill":{key:" ",collapsed:!0,format:{list:!1},prefix:/^(1\.|-|\*)$/,handler:function(t,e){var o=e.prefix.length;this.quill.scroll.deleteAt(t.index-o,o),this.quill.formatLine(t.index-o,1,"list",1===o?"bullet":"ordered",Quill.sources.USER),this.quill.setSelection(t.index-o,Quill.sources.SILENT)}},"pre wrap":{key:192,collapsed:!0,format:{"code-block":!1},prefix:/^``$/,offset:2,handler:function(t,e){var o=e.prefix.length,l=t.index-o;this.quill.scroll.deleteAt(l,o),this.quill.formatLine(l,1,"code-block",!0,Quill.sources.USER),this.quill.setSelection(l,Quill.sources.SILENT)}},code:{key:192,handler:function(t,e){if(!e.collapsed){var o=a.scroll.descendants(Block,t.index,t.length);if(o.length>1||1==o.length&&o[0]instanceof CodeBlock)return this.quill.format("code-block",!e.format["code-block"],Quill.sources.USER),!1;var l=a.scroll.descendants(BreakBlot,t.index,t.length);if(l.length)return this.quill.format("code-block",!e.format["code-block"],Quill.sources.USER),!1}return!(!e.collapsed||e.format.code||/\s$/.test(e.prefix))||void this.quill.format("code",!e.format.code,Quill.sources.USER)}},"figure delete":{key:Keyboard.keys.BACKSPACE,collapsed:!0,offset:0,handler:function(t,e){var o=a.scroll.line(t.index),l=_slicedToArray(o,2),r=l[0];l[1];return!(r&&r.prev&&r.prev instanceof FigureBlot)||(e.empty&&a.deleteText(t.index,1,Quill.sources.USER),a.setSelection(r.prev.offset(a.scroll)),!1)}},"field backspace":{key:Keyboard.keys.BACKSPACE,collapsed:!0,offset:0,handler:function(t,e){var o=a.scroll.line(t.index),l=_slicedToArray(o,2),r=l[0];l[1];return!(r&&r.prev&&r.prev instanceof FieldBlot&&$(r.domNode).text().length>0)}}}}}});return a.addContainer($tl_link_tooltip.get(0)),a.addContainer($tl_tooltip.get(0)),a.addContainer($tl_blocks.get(0)),a.on(Quill.events.EDITOR_CHANGE,function(t,e){if(t===Quill.events.SELECTION_CHANGE&&a.isEnabled()&&null!=e){checkFigureBlots(e),checkTooltips(e);var o=a.getFormat(e);$tl_article.toggleClass("title_focused",!(!o.blockTitle&&!o.blockAuthor)),checkOncePlaceholder()}}),a.on(Quill.events.TEXT_CHANGE,function(){a.getSelection();checkRequiredBlots(a),checkBlotPlaceholder(a),checkOncePlaceholder(),draftSave()}),a.on(Quill.events.TEXT_PASTE,function(){var t=a.getSelection();t&&r(t)}),a.on(Quill.events.SCROLL_OPTIMIZE,function(t){t.forEach(function(t){if("childList"==t.type&&!t.addedNodes.length&&t.removedNodes.length){var e=t.previousSibling,o=t.nextSibling;if(!o&&e&&"BR"==e.tagName&&"inline"==e.className){var l=document.createElement("br");l.className="inline",t.target.appendChild(l)}else!o||!e||"BR"==e.tagName&&"inline"==e.className||"BR"!=o.tagName||"inline"!=o.className||o.nextSibling||o.parentNode&&o.parentNode.removeChild(o)}})}),$(document).on("click touchstart",function(t){for(var e=t.target;e;){if(e===a.container)return;e=e.parentNode}hideFormatTooltip(),hideBlocksTooltip()}),checkRequiredBlots(a),checkBlotPlaceholder(a),a}function checkOncePlaceholder(){$(".placeholder_once").removeAttr("data-placeholder").removeClass("placeholder_once empty")}function checkBlotPlaceholder(t){var e=t.scroll.descendants(Block,0,t.scroll.length());e.forEach(function(t){if(t.domNode.hasAttribute("data-placeholder")){var e=$(t.domNode).text();$(t.domNode).toggleClass("empty",!e)}})}function checkRequiredBlots(t){var e=t.scroll.lines(),o=_slicedToArray(e,2),l=o[0],r=o[1];if(l instanceof BlockEmbed)t.updateContents((new Delta).insert("\n",{blockTitle:!0}).insert("\n",{blockAuthor:!0}),Quill.sources.SILENT);else if(l instanceof TitleBlot||t.formatLine(0,1,{blockTitle:!0},Quill.sources.SILENT),r){if(r instanceof BlockEmbed){var i=r.offset(t.scroll);t.updateContents((new Delta).retain(i).insert("\n",{blockAuthor:!0}),Quill.sources.SILENT)}else if(!(r instanceof AuthorBlot)){var a=r.offset(t.scroll);t.formatLine(a,1,{blockAuthor:!0},Quill.sources.SILENT)}}else{var n=t.scroll.length();t.updateContents((new Delta).retain(n).insert("\n",{blockAuthor:!0}),Quill.sources.SILENT)}var s=t.scroll.lines(),u=_slicedToArray(s,3),c=u[2];if(c){var d=c.offset(t.scroll),p=t.scroll.length()-d,h=t.scroll.descendants(FieldBlot,d,p);h.forEach(function(e){var o=e.offset(t.scroll),l=e.length(),r=e.constructor.blotName;t.formatText(o,l,r,!1,Quill.sources.SILENT)})}else{var f=t.scroll.length();t.insertText(f,"\n",Quill.sources.SILENT)}var _=t.scroll.lines();_.forEach(function(t,e){"P"==t.domNode.tagName&&(3==_.length&&2==e?t.domNode.setAttribute("data-placeholder","Your story..."):t.domNode.removeAttribute("data-placeholder"))})}function checkFigureBlots(t){var e=quill.scroll.descendant(FigureBlot,t.index),o=_slicedToArray(e,1),l=o[0],r=quill.scroll.descendants(FigureBlot,0,quill.scroll.length());r.forEach(function(t){l!==t&&t.blur()}),l&&(l.focus(),hideFormatTooltip(),hideBlocksTooltip())}function checkTooltips(t){var e=quill.scroll.descendant(Block,t.index),o=_slicedToArray(e,2),l=o[0];o[1];0===t.length?(hideFormatTooltip(),null==l||l instanceof FieldBlot||l instanceof BlockquoteBlot||l instanceof PullquoteBlot||l instanceof CodeBlock||l instanceof ListItem||$(l.domNode).text().length?hideBlocksTooltip():showBlocksTooltip(t)):(null==l||l instanceof TitleBlot?hideFormatTooltip():(showFormatTooltip(t),toolbarUpdate(t)),hideBlocksTooltip())}function updatePhoto(t,e){return"image/jpg"==t.type||"image/jpeg"==t.type?loadImage(t,function(o){if("error"===o.type)e(t);else if(o.toBlob)o.toBlob(function(t){e(t)},t.type);else{var l=o.toDataURL(t.type),r={type:t.type,base64_data:l.split(",")[1]};e(uploadDataToBlob(r))}},{canvas:!0,orientation:!0}):void e(t)}function uploadDataToBlob(t){for(var e=atob(t.base64_data),o=[],l=0;l"),o.html()):($("h1,address",o).remove(),$("br.inline",o).replaceWith("\n"),{data:JSON.stringify(wrapDomElement(o.get(0)).children),length:o.html().length})}function showError(t){$error_msg.text(t),clearTimeout($error_msg.to),$error_msg.addClass("shown"),$error_msg.to=setTimeout(function(){$error_msg.removeClass("shown")},3e3)}function savePage(){if($tl_article.hasClass("tl_article_saving"))return!1;var t=$("h1",$tl_content).text(),e=$("address",$tl_content).text(),o=$("address a",$tl_content).attr("href")||"";if(t.length<2){clearTimeout($tl_article.to),$tl_article.addClass("title_required"),$tl_article.to=setTimeout(function(){$tl_article.removeClass("title_required")},3e3),quill.focus();var l=quill.scroll.descendants(TitleBlot,0,quill.scroll.length()),r=_slicedToArray(l,1),i=r[0];return quill.setSelection(i.offset(),i.length()-1),quill.selection.scrollIntoView(),showError("Title is too small")}var a=$('img[src^="data:"],video[src^="data:"]');if(a.length)return showError("Upload in progress.\nPlease wait...");var n=getPageContent();if(n.length>65536)return showError("Content is too big");$tl_article.addClass("tl_article_saving"),updateEditable(!1);var s="---------------------------TelegraPhBoundary21",u="--"+s+'\r\nContent-Disposition: form-data; name="Data";filename="content.html"\r\nContent-type: plain/text\r\n\r\n'+n.data+"\r\n--"+s+'\r\nContent-Disposition: form-data; name="title"\r\n\r\n'+t+"\r\n--"+s+'\r\nContent-Disposition: form-data; name="author"\r\n\r\n'+e+"\r\n--"+s+'\r\nContent-Disposition: form-data; name="author_url"\r\n\r\n'+o+"\r\n--"+s+'\r\nContent-Disposition: form-data; name="save_hash"\r\n\r\n'+(T.saveHash||"")+"\r\n--"+s+'\r\nContent-Disposition: form-data; name="page_id"\r\n\r\n'+T.pageId+"\r\n--"+s+"--";$.ajax(T.apiUrl+"/save",{contentType:"multipart/form-data; boundary="+s,data:u,type:"POST",dataType:"json",xhrFields:{withCredentials:!0},success:function(t){return $tl_article.removeClass("tl_article_saving"),t.error?(updateEditable(!0),showError(t.error)):(draftClear(),void(!T.pageId&&t.path&&(location.href="/"+t.path)))},error:function(t){return $tl_article.removeClass("tl_article_saving"),updateEditable(!0),showError("Network error")}})}function checkAuth(){T.editable&&$.ajax(T.apiUrl+"/check",{data:{page_id:T.pageId},type:"POST",dataType:"json",xhrFields:{withCredentials:!0},success:function(t){if(t.save_hash&&(T.saveHash=t.save_hash),t.report_hash&&(T.reportHash=t.report_hash,$tl_page_footer.addClass("tl_page_footer_visible")),(t.can_edit&&T.saveHash||!T.pageId)&&(t.short_name&&$account.text(t.short_name),$tl_article.addClass("tl_article_editable")),!T.pageId&&($tl_article.addClass("tl_article_edit"),!draftGet()&&t.author_name)){if(t.author_url)var e={link:t.author_url};else var e={};var o=quill.scroll.descendants(AuthorBlot),l=_slicedToArray(o,1),r=l[0];r&&quill.updateContents((new Delta).retain(r.offset())["delete"](r.length()).insert(t.author_name,e),Quill.sources.USER)}if(t.auth_alert&&t.short_name){var i='

Success!

You are now logged in as '+htsc(t.short_name)+" in this browser.

";t.migrate_count>0&&t.migrate_hash?(i+="

We can also add "+t.migrate_count+" Telegraph page"+(t.migrate_count>1?"s":"")+" from this browser to your account.

",showAlert(i,{close_btn:"Skip",submit_btn:"Add",submit:function(){migratePages(t.migrate_hash)}})):showAlert(i,{close_btn:"Continue"})}pageContent=getPageContent(!0),updateEditable(isEdit())}})}function migratePages(t){$.ajax(T.apiUrl+"/migrate",{data:{migrate_hash:t},type:"POST",dataType:"json",xhrFields:{withCredentials:!0},success:function(t){t.migrated_count>0?showAlert('

Success!

Added '+t.migrated_count+" Telegraph page"+(t.migrated_count>1?"s":"")+' to your account.

To see a list of your pages, talk to the @Telegraph bot on Telegram.

',{close_btn:"Continue"}):hideAlert()}})}function toolbarUpdate(t){var e=null==t?{}:quill.getFormat(t),o=!!e.blockAuthor,l=!(!e.blockHeader&&!e.blockSubheader),r=!!e["code-block"];if($bold_button.toggleClass("active",!!e.bold),$bold_button.toggleClass("disabled",o||l||r),$italic_button.toggleClass("active",!!e.italic),$italic_button.toggleClass("disabled",o||l||r),$header_button.toggleClass("active",!!e.blockHeader),$header_button.toggleClass("disabled",o),$subheader_button.toggleClass("active",!!e.blockSubheader),$subheader_button.toggleClass("disabled",o),$quote_button.toggleClass("active",!(!e.blockBlockquote&&!e.blockPullquote)),$quote_button.toggleClass("pullquote",!!e.blockPullquote),$quote_button.toggleClass("disabled",o),null!=t){var i=quill.scroll.descendants(LinkBlot,t.index,t.length);$link_button.toggleClass("active",!!i.length)}else $link_button.toggleClass("active",!1);$link_button.toggleClass("disabled",r)}function storageSet(t,e){try{return localStorage.setItem(t,e),!!localStorage.getItem(t)}catch(o){return!1}}function storageGet(t){try{return localStorage.getItem(t)}catch(e){return!1}}function storageDelete(t){try{return localStorage.removeItem(t),!0}catch(e){return!1}}function draftClear(){storageDelete("draft")}function draftSave(){if(!pageContent)return!1;if(!T.pageId){var t=getPageContent(!0);if(pageContent!=t)return pageContent=t,storageSet("draft",t)}return!1}function draftGet(){return!T.pageId&&storageGet("draft")}function isEdit(){return $tl_article.hasClass("tl_article_edit")}function updateEditableText(t,e){"undefined"==typeof e&&(e=isEdit()),e?$(".editable_text:not(:has(.editable_input))",t).map(function(){var t=this.innerText,e=document.createElement("textarea");return e.classList.add("editable_input"),e.setAttribute("dir","auto"),e.setAttribute("tabindex","-1"),e.setAttribute("rows","1"),e.value=t,t||this.classList.add("empty"),$(this).empty().append(e),autosize(e),e}):$(".editable_text > .editable_input",t).map(function(){var t=this.value,e=this.parentNode;return $(e).empty().text(t),e})}function updateEditable(t){if($tl_article.toggleClass("tl_article_edit",t),updateEditableText(),window.quill&&(quill.enable(t),t&&quill.focus()),!t){var e=$("h1",$tl_content),o=$("address",$tl_content),l=$("address a",$tl_content).attr("href");$("h1",$tl_header).text(e.text()),$("address a",$tl_header).text(o.text()),l?$("address a",$tl_header).attr("href",l):$("address a",$tl_header).removeAttr("href"),hideLinkTooltip(),hideFormatTooltip(),hideBlocksTooltip()}}function updateReportFormState(){var t=$report_form.get(0),e=!t.reason.value||"copyright"==t.reason.value;$report_form.toggleClass("copyright_selected","copyright"==t.reason.value),$report_form.toggleClass("form_disabled",!!e),t.reason.value&&t.comment.focus()}function sendReport(){if($report_form.hasClass("form_disabled"))return!1;var t=$report_form.get(0);$report_popup.addClass("tl_popup_loading"),$.ajax(T.apiUrl+"/report",{data:{page_id:T.pageId,report_hash:T.reportHash,reason:t.reason.value,reason_text:t.comment.value},type:"POST",dataType:"json",xhrFields:{withCredentials:!0},success:function(t){$report_popup.removeClass("tl_popup_loading"),hidePopup(),showAlert('

Report sent

Telegraph moderators will review your report. Thank you!

',{close_btn:"Done"})}})}function showLinkTooltip(t,e){if(isEdit()){var o={index:t.offset(quill.scroll),length:t.length()};$tl_link_tooltip.text(decodeURI(e)),tooltipUpdatePosition($tl_link_tooltip,o,linkTTOptions),$tl_link_tooltip.hasClass("move_anim")||setTimeout(function(){$tl_link_tooltip.addClass("move_anim")},1),$tl_link_tooltip.hasClass("shown")||setTimeout(function(){$tl_link_tooltip.addClass("shown")},10)}}function hideLinkTooltip(){$tl_link_tooltip.removeClass("move_anim shown")}function showFormatTooltip(t){isEdit()&&($tl_tooltip.removeClass("tooltip_prompt"),tooltipUpdatePosition($tl_tooltip,t,formatTTOptions),$tl_tooltip.hasClass("move_anim")||setTimeout(function(){$tl_tooltip.addClass("move_anim")},10),$tl_tooltip.hasClass("shown")?tooltipUpdatePosition($tl_link_tooltip,null,linkTTOptions):setTimeout(function(){$tl_tooltip.addClass("shown"),tooltipUpdatePosition($tl_link_tooltip,null,linkTTOptions)},10))}function hideFormatTooltip(){$tl_tooltip.removeClass("move_anim shown"),tooltipUpdatePosition($tl_link_tooltip,null,linkTTOptions)}function showBlocksTooltip(t){isEdit()&&($tl_blocks.addClass("shown"),blocksUpdatePosition(t))}function hideBlocksTooltip(){$tl_blocks.removeClass("shown")}function hideAlert(){$(".tl_alert").remove()}function showAlert(t,e){e=e||{},e.close_btn=e.close_btn||"OK",e.submit_btn=e.submit_btn||!1,e.close=e.close||hideAlert,e.submit=e.submit||e.close,hideAlert();var o=$('
');$("section",o).html(t);var l=$("aside",o);if(e.close_btn){var r=$('');r.html(e.close_btn).click(e.close).appendTo(l)}if(e.submit_btn){var i=$('');i.html(e.submit_btn).click(function(){o.addClass("tl_popup_loading"),e.submit()}).appendTo(l)}o.appendTo("body")}function hidePopup(){$(".tl_popup").addClass("tl_popup_hidden")}function showPopup(t){hideAlert(),t.removeClass("tl_popup_hidden")}function isOverElement(t,e,o){if(!e||!e.hasClass("shown"))return!1;t.bottom=t.top+t.height,t.right=t.left+t.width;var l=e,r={top:l._top,bottom:l._top+e.outerHeight(),left:l._left,right:l._left+e.outerWidth()};return!(t.left-r.right>=o||r.left-t.right>=o||t.top-r.bottom>=o||r.top-t.bottom>=o)&&r}function tooltipUpdatePosition(t,e,o){if(o=o||{padding:10,position:"top"},e=e||t._range||null,null!=e){var l=quill.getBounds(e),r=$(quill.container).offset(),i={width:t.outerWidth(),height:t.outerHeight()},a={width:$(window).outerWidth(),height:$(window).outerHeight(),scrolltop:document.body.scrollTop},n={left:9,top:a.scrolltop+9},s={left:a.width-i.width-9,top:a.scrolltop+a.height-i.height-9};i.left=l.left+l.width/2-i.width/2;var u=r.left+i.left;us.left&&(i.left=s.left-r.left);var c=void 0;if("top"==o.position){i.top=l.top-i.height-o.padding;var d=r.top+i.top;c=!1,ds.top&&(i.top=l.top-i.height-o.padding,(p=isOverElement(i,o.depend,o.dependPadding))&&(i.top=p.top-i.height-o.dependPadding),c=!1)}i.left=Math.round(i.left),i.top=Math.round(i.top),t._range=e,o.minDelta&&Math.abs(i.left-t._left)/g,">").replace(/"/g,""").replace(/\'/g,"'").replace(/%/g,"%")}function toolbarPrompt(t,e,o){var l=$(".prompt_input",t),r=$(".close",t);l.val("").attr("placeholder",e),l.on("keydown",function(e){var r=e.which||e.keyCode;if(27==r)toolbarPromptHide(t);else if(13==r){var i=l.val();i&&(o&&o(i),e.preventDefault()),toolbarPromptHide(t)}}),l.on("blur",function(){toolbarPromptHide(t)}),r.on("click",function(){toolbarPromptHide(t)}),t.show().addClass("tooltip_prompt"),l.focus()}function toolbarPromptHide(t){var e=$(".prompt_input",t),o=$(".close",t);e.off("keydown"),e.off("blur"),o.off("click"),t.show().removeClass("tooltip_prompt"),quill.focus()}var _slicedToArray=function(){function t(t,e){var o=[],l=!0,r=!1,i=void 0;try{for(var a,n=t[Symbol.iterator]();!(l=(a=n.next()).done)&&(o.push(a.value),!e||o.length!==e);l=!0);}catch(s){r=!0,i=s}finally{try{!l&&n["return"]&&n["return"]()}finally{if(r)throw i}}return o}return function(e,o){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,o);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),_createClass=function(){function t(t,e){for(var o=0;o=0?e:t.data.length),t.previousSibling?o+this._index(t.previousSibling,-1):t.parentNode?o+this._index(t.parentNode,-1):0}},{key:"_position",value:function(t,e){if(t.nodeType==t.TEXT_NODE)return e<=t.data.length?[t,e]:(e-=t.data.length,[null,e]);for(var o=t.firstChild;o;){var l=null,r=this._position(o,e),i=_slicedToArray(r,2);if(l=i[0],e=i[1],l)return[l,e];o=o.nextSibling}return[t,e]}},{key:"update",value:function(t){this.domCursor.innerHTML=""}},{key:"index",value:function(t,e){return 0}},{key:"position",value:function(t,e){return[this.domCursor,0]}}],[{key:"value",value:function o(t){var o={caption:""},e=t.querySelector("img");e&&(o.image=e.src);var l=t.querySelector("video");l&&(o.video=l.src);var r=t.querySelector("iframe");r&&(o.embed=r.src);var i=t.querySelector("figcaption");if(i){var a=i.querySelector(".editable_input");a?o.caption=a.value:o.caption=i.innerText}return o}}]),e}(BlockEmbed);FigureBlot.blotName="blockFigure",FigureBlot.tagName="figure",Quill.register(FigureBlot);var MyQuill=function(t){function e(){return _classCallCheck(this,e),_possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return _inherits(e,t),_createClass(e,[{key:"formatLine",value:function(){for(var t,o=arguments.length,l=Array(o),r=0;r0?"mailto:"+t:"http://"+t),quill.focus(),quill.format("link",t),toolbarUpdate(l)})}),$header_button.click(function(t){var e=t.target,o=e.classList.contains("active");t.preventDefault();var l=quill.getSelection(!0);quill.format("blockHeader",!o);var r=quill.scroll.descendants(HeaderBlot,l.index,l.length);r.forEach(function(t){var e=t.offset(quill.scroll),o=t.length();quill.formatText(e,o,{bold:!1,italic:!1,code:!1},Quill.sources.SILENT)}),quill.updateSelection(Quill.sources.API)}),$subheader_button.click(function(t){var e=t.target,o=e.classList.contains("active");t.preventDefault();var l=quill.getSelection(!0);quill.format("blockSubheader",!o);var r=quill.scroll.descendants(SubheaderBlot,l.index,l.length);r.forEach(function(t){var e=t.offset(quill.scroll),o=t.length();quill.formatText(e,o,{bold:!1,italic:!1,code:!1},Quill.sources.SILENT)}),quill.updateSelection(Quill.sources.API)}),$quote_button.click(function(t){var e=t.target,o=e.classList.contains("active"),l=e.classList.contains("pullquote");t.preventDefault();quill.getSelection(!0);o?quill.format("blockPullquote",!l):quill.format("blockBlockquote",!0),quill.updateSelection(Quill.sources.API)}),$image_button.click(function(){if(T.uploadEnabled){var t=quill.container.querySelector("input.ql-image[type=file][data-status=ready]");null==t&&(t=document.createElement("input"),t.setAttribute("type","file"),t.setAttribute("accept",browser.safari_mobile?"image/gif, image/jpeg, image/jpg, image/png":"image/gif, image/jpeg, image/jpg, image/png, video/mp4"),t.classList.add("ql-image"),t.addEventListener("change",function(){if(null!=t.files&&null!=t.files[0]){var e=t.files[0];updatePhoto(e,function(e){if(quill.fileSizeLimit&&e.size>quill.fileSizeLimit)return quill.fileSizeLimitCallback&&quill.fileSizeLimitCallback();var o=new FileReader;o.onload=function(e){getFigureValueByUrl(e.target.result,function(e){if(e){var o=quill.getSelection(!0);quill.updateContents((new Delta).retain(o.index)["delete"](o.length).insert({blockFigure:e}),Quill.sources.USER)}else showError("Invalid file format");t.value="",t.setAttribute("data-status","ready")})},o.readAsDataURL(e)})}}),quill.container.appendChild(t)),t.setAttribute("data-status","busy"),t.click()}else{var e=quill.getSelection(!0),o=quill.scroll.line(e.index),l=_slicedToArray(o,1),r=l[0];if(r){var i=$(r.domNode).text();i||(r.domNode.setAttribute("data-placeholder","Paste a link to image or video and press Enter"),$(r.domNode).addClass("placeholder_once empty"),hideBlocksTooltip())}}}),$embed_button.click(function(t){var e=quill.getSelection(!0),o=quill.scroll.line(e.index),l=_slicedToArray(o,1),r=l[0];if(r){var i=$(r.domNode).text();i||(r.domNode.setAttribute("data-placeholder","Paste a YouTube, Vimeo or Twitter link, and press Enter"),$(r.domNode).addClass("placeholder_once empty"),hideBlocksTooltip())}}),$publish_button.click(function(){savePage()}),$edit_button.click(function(){updateEditable(!0)}),$report_button.click(function(){var t=$report_form.get(0);t.reset(),updateReportFormState(),showPopup($report_popup)}),$report_form.submit(function(t){t.preventDefault(),sendReport()}),$report_form.find("input[type=radio]").change(function(){updateReportFormState()}),$report_cancel.click(function(){hidePopup()}),$(window).on("scroll resize",function(){tooltipUpdatePosition($tl_tooltip,null,formatTTOptions),tooltipUpdatePosition($tl_link_tooltip,null,linkTTOptions)}),(new Image).src=window.devicePixelRatio>=2?"/images/icons_2x.png?1":"/images/icons.png?1";var quill=initQuill(),pageContent=!1;browser.mobile&&$(document.body).addClass("mobile"),checkAuth();